<%@ page import="com.examination.bean.User" %><%--
  Created by IntelliJ IDEA.
  User: set_free
  Date: 020
  Time: 12:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--引入标签库--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--项目名必须写--%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>在线考试系统登录页面</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/common/css/reset.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/common/css/styles.css">

</head>
<body>
<div class="htmleaf-container">

    <div class="wrapper">

        <div class="container">
            <h1 id="add">注册账号</h1> <br><br>
            <span style="color:red">${requestScope.get("errorInfo")}</span>
            <form class="form" id="register_form" action="${ctx}/RegisterServlet?methodName=registerUser" method="post">
                <input type="text" placeholder="新注册账户" name="name" id="name">
                <input type="password" placeholder="输入密码" name="password" id="password">
                <input type="password" placeholder="再输入一次密码" name="newword" id="newword">
                <div>
                    <span>请选择注册身份:</span>
                    <select id="role_type" name="roleType">
                        <option value="student">学生</option>
                        <option value="teacher">老师</option>
                        <option value="admin">管理员</option>
                    </select><br/>
                </div>
                <br>
                <button type="submit" id="login-button">注册</button>
                <button type="button" id="button" onclick="window.location.href='${ctx}/index.jsp'">登录</button>
            </form>
        </div>

        <ul class="bg-bubbles">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</div>
</body>
<script src="${ctx}/common/jquery/jquery-3.5.0.js" type="text/javascript"></script>
<script>

    $(document).ready(function() {
        $("#register_form").submit(function(e){
            var account = $("input[name='account']").val();
            var password = $("input[name='password']").val();
            var newword = $("input[name='newword']").val();
            if (password != newword){
                alert("再次输入的密码与设置密码不相同！请牢记密码！");
                return false;
            }
            if (!account && !password) {
                alert("账号或密码不能为空！");
                return false;
            }
            var formData = $(this).serialize();
            regUser(formData);
            return false;
        });
        //方法跳转
        function regUser(formData){
            $.ajax({
                url:"${ctx}/RegisterServlet?methodName=registerUser",
                data:formData,
                type:"post",
                success:function(result){
                    if(result.state == '200'){
                        alert("数据添加成功");
                        window.location.href="${ctx}/index.jsp";
                    }
                }
            });
        }
    });
</script>